package com.ruoyi.project.app.controller;

/**
 * @description: 打印日志类
 * @author: hanruiyu
 * @create: 2020-10-17 14:26
 **/


import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.text.SimpleDateFormat;
import java.util.Date;

public class LogWrite {

    private File logFile = null;
    private SimpleDateFormat dateFormat =
            new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    public LogWrite(File logFile) {
        this.logFile = logFile;
    }

    public void logMsg(File logFile, String msgInfo) throws IOException {

        if (!logFile.exists()) {
            logFile.createNewFile();
        }

        Writer txtWriter = new FileWriter(logFile, true);
        txtWriter.write(dateFormat.format(new Date()) + "\t" + msgInfo + "\n");
        txtWriter.flush();
        txtWriter.close();
    }

}
